package com.hyb.algorithm.data.struct.dp;

/**
 * @Author: huyanbing
 * @Date: 2021/9/8 7:13 下午
 *
 * https://leetcode-cn.com/problems/number-of-1-bits/
 *
 * 191  191. 位1的个数
 *
 *
 */
public class HammingWeight {


    public static void main(String[] args) {

        HammingWeight exe = new HammingWeight();
        int ret = exe.hammingWeight(7);
        System.out.println(ret);
    }

    public int hammingWeight(int n) {

        int res = 0;
        while (n != 0) {
            n = n & (n - 1);
            res++;
        }

        return res;
    }

}
